package ch.ethz.fcl.metrobuzz.controller.gui.twl.examples;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import ch.ethz.fcl.metrobuzz.MBContainer;
import ch.ethz.fcl.metrobuzz.controller.MBController;
import ch.ethz.fcl.metrobuzz.tools.MBGL;
import ch.ethz.fcl.metrobuzz.viewer.MBViewer;
import ch.ethz.fcl.metrobuzz.viewer.MBViewer.ProjectionType;

public class TWLTest {
	private MBViewer view;
	private MBController control;

	public TWLTest() {
		init();
	}

	public void run() {
		while (!Display.isCloseRequested()) {
			GL11.glPushMatrix();

			MBGL.enableBlend();
			view.update();
			render();

			control.update();

			GL11.glDisable(GL11.GL_BLEND);

			GL11.glPopMatrix();

			Display.update();
			Display.sync(32);
		}

		Display.destroy();
	}

	private void init() {
		MBContainer container = new MBContainer();

		view = new MBViewer(ProjectionType.Perspective, container);
		view.createDisplay(427, 805, 427, 805, "TWL Test");
		control = new MBController(container);
		control.setEventInterval(50);

		Display.setTitle("TWL Test");

		GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
	}

	private void render() {
		GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

		GL11.glColor4f(1, 0, 0, 1.0f);
		GL11.glPointSize(5.0f);
		GL11.glBegin(GL11.GL_LINES);
		GL11.glVertex2d(0, 0);
		GL11.glVertex2d(0.5f, 0.5f);
		GL11.glEnd();
	}

	public static void main(String[] args) {
		new TWLTest().run();
	}
}
